using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using dender.dvdcover.gui.custom;
using dender.dvdcover.core;
using System.Drawing.Printing;
using dender.dvdcover.gui.Properties;
using dender.dvdcover.core.image;

namespace dender.dvdcover.gui
{
    public partial class mainForm : Form
    {
        private Cover mCover;
        public Cover Cover
        {
            get
            {
                return mCover;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("Cover");

                mCover = value;
                //Set the cover to the coverTabControl
                coverTabControl.Cover = mCover;
            }
        }

        public mainForm()
        {
            InitializeComponent();
        }

        private void mainForm_Load(object sender, EventArgs e)
        {
            // Let user directley choose the right format
            coverForm form = new coverForm();
            form.Owner = this;
            form.ShowDialog();

        }

        private void buttonPreferences_Click(object sender, EventArgs e)
        {
            settingForm form = new settingForm();
            form.Owner = this;
            form.ShowDialog();
        }

        private void buttonPrint_Click(object sender, EventArgs e)
        {
            if (this.Cover != null)
            {
                CoverPrintDocument document = this.Cover.GeneratePrintDocument();
                PrintPreviewDialog preview = new PrintPreviewDialog();
                preview.Document = document;
                preview.ShowDialog();
            }             
            
        }

        private void buttonAddImage_Click(object sender, EventArgs e)
        {
            if (openImageDialog.ShowDialog() == DialogResult.OK)
            {         
                CoverTabPage selected = (CoverTabPage)this.coverTabControl.SelectedTab;
                CoverPart p = selected.PartPictureBox.Part;
                CoverImage image = new CoverImage(p, openImageDialog.FileName);
                p.Fill(image);
            }
        }

        private void buttonAbout_Click(object sender, EventArgs e)
        {
            AboutBox about = new AboutBox();
            about.Owner = this;
            about.ShowDialog();

        }
    }
}